﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class provides the scanning or sampling of trigonometric polynomial in an interval
    /// of [0...2PI].
    /// </summary>
    [Serializable]
    public class TrigonometricPolynomialSampler : AbstractPolynomialSampler
    {
        /// <summary>
        /// The trigonometric polynomial to scan.
        /// </summary>
        private TrigonometricPolynomial polynomial;

        /// <summary>
        /// Initializes a new instance of the <see cref="TrigonometricPolynomialSampler"/> class.
        /// </summary>
        /// <param name="polynomial">The trigonometric polynomial to sample or scan.</param>
        public TrigonometricPolynomialSampler(TrigonometricPolynomial polynomial)
        {
            this.polynomial = polynomial;
        }

        /// <summary>
        /// Gets or sets the trigonometric polynomial to sample or scan.
        /// </summary>
        /// <value>The trigonometric polynomial to sample or scan.</value>
        public TrigonometricPolynomial Polynomial
        {
            get { return polynomial; }
            set { polynomial = value; }
        }

        /// <summary>
        /// Samples or scans the polynomial in an interval of [0...2PI].
        /// </summary>
        /// <param name="numberOfSamples">The number of samples.</param>
        /// <returns>The results of the sampling process in form of plane points.</returns>
        public Point2D[] SamplePolynomial(int numberOfSamples)
        {
            double currentSampleValue = 0;
            double samplerate = (2 * Math.PI) / numberOfSamples;
            Point2D[] result = new Point2D[numberOfSamples];

            for (int i = 0; i < numberOfSamples; i++)
            {
                result[i] = new Point2D(currentSampleValue, this.polynomial.SolveAt(currentSampleValue));
                currentSampleValue += samplerate;
            }

            return result;
        }
    }
}